﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace XCommunity.Web
{
  public class WebCommunityModule : IHttpModule
  {

    HttpApplication _application;

    public void Init( HttpApplication context )
    {
      _application = context;
      context.BeginRequest += OnBeginRequest;
      context.PostRequestHandlerExecute += OnPostRequestHandlerExecute;
    }

    private void OnBeginRequest( object sender, EventArgs e )
    {
      AccountContext accountContext = AccountContext.Create( _application.Context );
      accountContext.CoockiesInit();
    }

    private void OnPostRequestHandlerExecute( object sender, EventArgs e )
    {
      AccountContext.Current.CookiesWrite();
    }


    public void Dispose()
    {
      //Do Nothing
    }

  }
}
